﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class FSMState
{
    //FSMSystem的对象
    protected FSMSystem fsms;
    //状态的名字
    protected string name;
    public string Name { get { return name; } }
    //装换条件和转换到的状态的映射
    protected Dictionary<Transition, string> map = new Dictionary<Transition, string>();
    //添加“线”
    public void AddTranstion(Transition transition, string stateName)
    {
        //检查是否符合添加条件
        if (transition == Transition.NULL || stateName == "")
            return;
        //检查map中是否已经存在
        if (!map.ContainsKey(transition))
        {
            map.Add(transition, stateName);
        }
    }
    //删除“线”
    public void DelateTransition(Transition transition, string stateName)
    {
        //检查是否符合添加条件
        if (transition == Transition.NULL || stateName == "")
            return;
        //检查map中是否已经存在
        if (map.ContainsKey(transition))
        {
            map.Remove(transition);
        }
    }
    //获得转换到的状态的名字
    public string GetOutState(Transition transition)
    {
        if (map.ContainsKey(transition))
        {
            return map[transition];
        }
        else
            return null;
    }
    //进入状态之前要做的事情
    public virtual void DoBeforeEnter() { }
    //进入状态后要做的事情
    public virtual void DoAfterEnter() { }
    //检测转换
    public abstract void Reason();
    //控制行为
    public abstract void Act(); 
}
